// pages/lister/lister.js
const {shebeilist, scanCodeBangding,quxiao,shanchu,payment,lookwuliu,lookmember,eqbangding} =require('../../util/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModalStatus:false,
    show:false,
    showtel:false,
    type:0,
    name:"",
    tel:"",
    alllist:[],
    nopaylist:[],
    nosendlist:[],
    daianzhuanglist:[],
    yianzhuanglist:[],
    yiquxiaolist:[],

  },
  quxiao(){
    this.setData({
      showtel:false,
      showModalStatus:false
    })
  },
  call(){
    wx.makePhoneCall({
      phoneNumber: this.data.tel 
    })
  },
  lookmember(e){
   
     let p={
      id:e.currentTarget.dataset.id
     }
     lookmember(p).then(res=>{
       console.log(res)
      this.setData({
       name:res.name  ,
       tel:res.phone,
       showtel:true,
       showModalStatus:true
      })
     
      console.log(this.data.name,this.data.tel)
     })
     
    

    console.log(e)
  },
  showModal: function () {
    // 显示遮罩层
     var animation= wx.createAnimation({
       duration: 200,
       timingFunction: "linear",
       delay: 0
     })
     this.animation = animation
     animation.translateY(300).step()
     this.setData({
       animationData: animation.export(),
       showModalStatus: true
     })
     setTimeout(function () {
       animation.translateY(0).step()
       this.setData({
         animationData: animation.export(),
         
       })
     }.bind(this), 200)
     this.setData({
      show:true
     })
    
   },
   hideModal: function () {
   
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
    this.setData({
      show:false
     })
    

  },
  chakanwuliu(e){

    this.showModal();
    
    console.log(e)
    
    this.setData({
      recordId:e.currentTarget.dataset.orderno.id,
     
    })
    let p={
      memberId:wx.getStorageSync('memberId'),
      recordId:this.data.recordId
    }
    console.log(p)
    lookwuliu(p).then(res=>{
      if(res.data.logisticsData.length==0){
        wx.showToast({
          title: '未查到物流信息',
          icon: 'error',
          duration: 2000
        })
      }else{
        console.log(res)
        this.setData({
          wuliulist:res.data.logisticsData,
          kuaidigongsi:res.data.typeName,
          kuaididanhao:res.data.number
        })
      }
      console.log(res)
    })

  },
  gopay(e){
   
    let p = {
      id:e.currentTarget.dataset.id,
      payType:0,
      type:0
     }
    payment(p).then(res=>{
      if(res.code==200){
      wx.requestPayment({
        timeStamp: res.data.timeStamp,
        nonceStr: res.data.nonceStr,
        package: res.data.package,
        signType: res.data.signType,
        paySign: res.data.sign,
        success (res) {
          console.log("支付成功 ")
          wx.showModal({
            title:'提示',
            content:'支付成功',
            success (res) {
             if (res.confirm) {
               wx.navigateBack({
                 delta: 1,
               })
              }
           }
          })
         },
        fail (res) { 
          console.log("支付失败 ")
          wx.showToast({
            title: "支付失败",
            icon: 'error',
            duration: 2000
          })
        }
      })}else{
        wx.showToast({
          title: res.msg,
          icon: 'error',
          duration: 2000
        })
      }
     })
 
  },
  off(){
    this.hideModal()
    this.setData({
      show:false
    })
  },
  scan(options){
    let that = this
    wx.scanCode({
      success: (res)=>  {
       
        let code = res.result
        wx.showModal({
          title: '提示',
          content:'请点击确认激活设备',
          success (res) {
            if (res.confirm) {
              let p = {
                memberId:wx.getStorageSync('memberId'),
                eqCode:code,
               
               
              }
              eqbangding(p).then(res=>{
                if(res.code == 200)
                {
                  wx.showToast({
                    title: '激活成功',
                    icon:'none'
                  })
                  that.onShow()
                }
                else
                {
                  wx.showToast({
                    title: res.msg,
                    icon:'none'
                  })
                }
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    })

  },
  delete(e){
    let that=this
    wx.showModal({
      title: '提示',
      content: '确定删除此订单',
      success (res) {
        if (res.confirm) {
          
          let p={
            memberId:wx.getStorageSync('memberId'),
            recordId:e.currentTarget.dataset.orderno
          }
          shanchu(p).then(res=>{
            that.onShow()
            
          })

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
 
  
   
  },
  cancel(e){
    let that=this
     wx.showModal({
       title: '提示',
       content: '确定取消此订单',
       success (res) {
         if (res.confirm) {
         
           let p={
             memberId:wx.getStorageSync('memberId'),
             recordId:e.currentTarget.dataset.orderno
           }
           quxiao(p).then(res=>{
             that.onShow()
             
           })
 
         } else if (res.cancel) {
           console.log('用户点击取消')
         }
       }
     })
     
   },
  bindchange(e){
    this.setData({
      type:e.detail.current
    })
    
  },
  handtapall(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
  },
  handtap1(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
  },

  handtap2(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
  },

  handtap3(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
  },

  handtap4(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
  },

  handtap5(e){
    this.setData({
      type:e.currentTarget.dataset.type
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this 
    wx.getSystemInfo({ 
        success: function (res) { 
            that.setData({ 
                clientHeight: res.windowHeight 
            }); 
        } 
    }) 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
//全部订单
    let p={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:6
    }
    shebeilist(p).then(res=>{
      
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
    
      this.setData({
        alllist:res.data.datas
      })
      console.log("全部",this.data.alllist)
      
    })
    //待付款订单
    let pa={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:0
    }
    shebeilist(pa).then(res=>{
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
      this.setData({
        nopaylist:res.data.datas
      })
      console.log("代付款",this.data.nopaylist)
    })
    //待发货订单
    let par={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:1
    }
    shebeilist(par).then(res=>{
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
      this.setData({
        nosendlist:res.data.datas
      })
      console.log("待发货",this.data.nosendlist)
    })
    //待安装订单
    let parm={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:5
    }
    shebeilist(parm).then(res=>{
     
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
      this.setData({
        daianzhuanglist:res.data.datas
      })
     
    })
    let d={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:2
    }
    shebeilist(d).then(res=>{
       console.log(res)
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
      this.setData({
        daianzhuanglist:this.data.daianzhuanglist.concat(res.data.datas)
      })
      console.log("待安装订单",this.data.daianzhuanglist)
    })
    // 已安装订单
    let parms={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:3
    }
    shebeilist(parms).then(res=>{
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
      this.setData({
        yianzhuanglist:res.data.datas
      })
      console.log("已安装",this.data.yianzhuanglist)
    })
    //已取消订单
    let pp={
      memberId:wx.getStorageSync('memberId'),
      pageNum:1,
      payStatus:4
    }
    shebeilist(pp).then(res=>{
      for(let i=0;i< res.data.datas.length;i++){
        let arr=[];
        arr= res.data.datas[i].aaEquipmentType.etImgs.split(",")
        res.data.datas[i].aaEquipmentType.arr=arr;
       
      }
      this.setData({
        yiquxiaolist:res.data.datas
      })
      console.log("已取消",this.data.yiquxiaolist)
    })






  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '分享小程序',
      imageUrl: 'https://anjingbao.anjingbao.net/profile/upload/renwufenxianginfo.jpg',
      path:"/pages/shouye/shouye",//当前页面 path ，必须是以 / 开头的完整路径
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }
    }
  }
})